/*
141. 环形链表
给定一个链表，判断链表中是否有环。
 */

/**
 * @param {ListNode} head
 * @return {boolean}
 */
var hasCycle = function (head) {
  if (!head || !head.next) {
    return false
  }
  let fast = head
  let slow = head
  do {
    fast = fast.next ? fast.next.next : fast.next
    slow = slow.next
  } while (fast !== slow && fast && slow)
  return fast === slow
}
